package com.InsideGamer.SuperJailBreak;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class UserCommands implements CommandExecutor
{
	private JailBreak plugin;
	
	public UserCommands ( JailBreak pluginInstance )
	{
		plugin = pluginInstance;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command command, String commandLine, String[] args)
	{
		Player player = null;
		
		if (sender instanceof Player)
		{
			player = (Player) sender;
		}
		
		if ( command.getName().equalsIgnoreCase ( "hire" ) )
		{
			// This command can be run from server and player.
			plugin.getServer().broadcastMessage ( ChatColor.RED + player.getName() + " wilt een perceel huren!" );
			
			return true;
		}
		
		if ( command.getName().equalsIgnoreCase ( "pay" ) )
		{
			// This command can be run from server and player.
			try {
			Player target = plugin.getServer().getPlayer(args[0]);
			plugin.users.ChangeMoneyTo ( player, target, args[1] );
			}
			catch (CommandException e)
			{
				plugin.BroadcastMessage(e.getMessage());
			}
			return true;
		}
		
		return false;
	}
	
	// https://github.com/imjake9/SimpleJail/blob/master/com/imjake9/simplejail/SimpleJail.java
	// http://code.google.com/p/basicbukkit/source/browse/trunk/src/nint22/basicbukkit/BasicProtectionCommands.java
}
